<!DOCTYPE HTML>
<html lang="en">
<head>
<title>RunAs - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The RunAs command specifies a set of user credentials to use for all subsequent uses of Run and RunWait commands." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>RunAs</h1>

<p>Specifies a set of user credentials to use for all subsequent uses of <a href="Run.htm">Run</a> and <a href="Run.htm">RunWait</a>.</p>

<pre class="Syntax"><span class="func">RunAs</span> <span class="optional">, User, Password, Domain</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>User</dt>
  <dd><p>If this and the other parameters are all omitted, the RunAs feature will be turned off, which restores <a href="Run.htm">Run</a> and <a href="Run.htm">RunWait</a> to their default behavior. Otherwise, this is the username under which new processes will be created.</p></dd>

  <dt>Password</dt>
  <dd><p><em>User</em>'s password.</p></dd>

  <dt>Domain</dt>
  <dd><p><em>User</em>'s domain. To use a local account, leave this blank. If that fails to work, try using @YourComputerName.</p>
    </dd>

</dl>
<h2>Remarks</h2>
<p>If the script is running with restricted privileges due to User Account Control (UAC), any programs it launches will typically also be restricted, even if RunAs is used. To elevate a process, use <a href="Run.htm#RunAs">Run *RunAs</a> instead.</p>
<p>This command does nothing other than notify AutoHotkey to use (or not use) alternate user credentials for all subsequent uses of <a href="Run.htm">Run</a> and <a href="Run.htm">RunWait</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is not changed by this command. If an invalid <em>User</em>, <em>Password</em>, or <em>Domain</em> is specified, <a href="Run.htm">Run</a> and <a href="Run.htm">RunWait</a> will display an error message explaining the problem (unless their <a href="Run.htm#UseErrorLevel">UseErrorLevel option</a> is in effect).</p>
<p>While the RunAs feature is in effect, <a href="Run.htm">Run</a> and <a href="Run.htm">RunWait</a> will not able to launch documents, URLs, or system verbs. In other words, the file to be launched must be an executable file.</p>
<p>The &quot;Secondary Logon&quot; service must be set to manual or automatic for this command to work (the OS should automatically start it upon demand if set to manual).</p>
<h2>Related</h2>
<p><a href="Run.htm">Run</a>, <a href="Run.htm">RunWait</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>RunAs, Administrator, MyPassword
Run, RegEdit.exe
RunAs  <em>; Reset to normal behavior.</em></pre>
</div>

</body>
</html>
